package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.Camp;
import com.ruoyi.camp.service.ICampService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/camp/camp")
public class CampController extends BaseController
{
    @Autowired
    private ICampService campService;

    /**
     * 查询营地列表
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:list')")
    @GetMapping("/list")
    public TableDataInfo list(Camp camp)
    {
        startPage();
        List<Camp> list = campService.selectCampList(camp);
        return getDataTable(list);
    }

    /**
     * 导出营地列表
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:export')")
    @Log(title = "营地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Camp camp)
    {
        List<Camp> list = campService.selectCampList(camp);
        ExcelUtil<Camp> util = new ExcelUtil<Camp>(Camp.class);
        util.exportExcel(response, list, "营地数据");
    }

    /**
     * 获取营地详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:query')")
    @GetMapping(value = "/{campid}")
    public AjaxResult getInfo(@PathVariable("campid") String campid)
    {
        return success(campService.selectCampByCampid(campid));
    }

    /**
     * 新增营地
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:add')")
    @Log(title = "营地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Camp camp)
    {
        return success(campService.insertCamp(camp));
    }

    /**
     * 修改营地
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:edit')")
    @Log(title = "营地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Camp camp)
    {
        return toAjax(campService.updateCamp(camp));
    }

    /**
     * 删除营地
     */
    @PreAuthorize("@ss.hasPermi('camp:camp:remove')")
    @Log(title = "营地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{campids}")
    public AjaxResult remove(@PathVariable String[] campids)
    {
        return toAjax(campService.deleteCampByCampids(campids));
    }
}
